﻿using T4UtilityBelt.UxDesigns;
using T4UtilityBelt.UxDesigns.Controls;

namespace T4UtilityBelt.DataDesigns
{
    public class EnumProperty : EntityProperty
    {
        public EnumProperty() 
            : base(null)
        {

        }

        public EnumProperty(string propertyType, string name)
            : base(propertyType, name)
        { }

        public EnumProperty(string propertyType, string name, bool required)
            : base(required ? propertyType : propertyType + "?", name, required)
        { }

        public override string RenderInterfaceServiceCs()
        {
            return string.Format("{1} {0}Value {{ get; set; }}", Name, "string");
        }

        public override string RenderAssignFromModelToServiceCs(string toControl, string fromControl)
        {
            return string.Format("{1}.{0}Value = {2}.{0}.ToString();", Name, toControl, fromControl);
        }

        public override string RenderAssignFromServiceToModelCs(string toControl, string fromControl)
        {
            return string.Format("{1}.{0} = ({3})Enum.Parse(typeof({3}), {2}.{0}Value);", Name, toControl, fromControl, PropertyType);
        }

        public override UxDesigns.Control CreateControl()
        {
            return new EnumControl(this);
        }

        public override string GetSqlType()
        {
            return "int";
        }
    }
}